var utils = require('../../../../utils/util.js');
var c = require('../../../../utils/config.js');
Page({
  data: {
    bill_nav: [
      '收入记录',
      '支出记录'
    ],
    total_name: '总收入',
    total_money: 0,
    select: 0,
    filter_nav: [
      '全部',
      '鼓励金',
      '招商奖',
      '收益转出',
      '系统增加',
      '系统减少',
    ],
    ym: '',
    status: 1,
    type: 0,
    select2: 0,
    filterH: 0,
    cutover: false,
    lists: []
  },
  onShow: function () {
    utils.checkLogin();
    this.getList();
  },
  //下拉刷新
  // onPullDownRefresh: function () {
  //   this.setData({
  //     lists: [],
  //     ym: '',
  //   });
  //   this.getList();
  // },
  //上拉加载
  // onReachBottom: function () {
  //   this.setData({
  //     lists: [],
  //     ym: '',
  //   });
  //   this.getList();
  // },

  getList: function () {
    var that = this;
    var token = wx.getStorageSync("userinfo").wap_token;
    var data = {
      url: "/yluser/usershouyi/lists",
      token: token,
      ym: this.data.ym,
      type: this.data.type,
      status: this.data.status,
    };
    utils.request(data).then(function (res) {
      if (res.code == 0) {
        var data = res.data.list
        var total = parseFloat(0);
        data.forEach((item, index) => {
          total += parseFloat(item.money);
        });
        that.setData({
          lists: data,
          ym: res.data.ym,
          total_money: total.toFixed(2)
        });
        wx.stopPullDownRefresh();
      }
    });
  },

  select_nav: function (e) {
    let k = e.currentTarget.dataset.index;
    // 0 |收入  1 |支出
    var value = 0;
    var total_name = '';
    switch (k) {
      case 0:
        value = 1;
        total_name = '总收入';
        break;
      case 1:
        value = -1;
        total_name = '总支出';
        break;
      default:
        value = 0;
        total_name = '总收入';
        break;
    }
    this.setData({
      select: k,
      status: value,
      total_name: total_name,
      ym: '',
      type: 0
    })
    this.getList();
  },
  filter_tab: function (e) {
    let k = e.currentTarget.dataset.index;
    /**
     * '鼓励金',
      '招商奖',
      '收益转出',
      '系统增加',
      '系统减少',
     */
    var value = 0;
    switch (k) {
      case 0:
        value = 0;
        break;
      case 1:
        value = 102;
        break;
      case 2:
        value = 109;
        break;
      case 3:
        value = 207;
        break;
      case 4:
        value = 101;
        break;
      case 5:
        value = 201;
        break;
      default:
        value = 0;
        break;
    }
    this.setData({
      select2: k,
      type: value,
      ym: '',
      cutover: false
    })
    this.getList();
  },
  openfilter: function () {
    let cutover = this.data.cutover
    this.setData({
      cutover: !cutover
    })
    if (cutover == true) {
      this.setData({
        filterH: 0
      })
    } else {
      this.scroll_distance()

    }
  },
  scroll_distance: function () {
    this.setData({
      filterH: 96
    })
  },
  bindDateChange: function (e) {
    //console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      ym: e.detail.value
    })
    this.getList();
  }
})